//
//  CommUtls.m
//  iosMathExample
//
//  Created by 李群 on 2021/9/18.
//

#import "CommUtls.h"
#import <UIKit/UIKit.h>

@implementation CommUtls
// 是否刘海屏
+ (BOOL)isIPhoneXSeries{
    BOOL iPhoneXSeries = NO;
    if ((UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone)) {
        return iPhoneXSeries;
    }
    if (@available(iOS 11.0, *)) {
        UIWindow *mainWindow = [self mainWindow];
        if (mainWindow.safeAreaInsets.bottom > 0) {
            iPhoneXSeries = YES;
        }
    }
    return iPhoneXSeries;
}

/**
 获取当前的window，不一定是keywindow
 @return 当前window
 */
+ (UIWindow*)mainWindow{
    id appDelegate = [UIApplication sharedApplication].delegate;
    if (appDelegate && [appDelegate respondsToSelector:@selector(window)]) {
        return [appDelegate window];
    }
    
    
    NSArray *windows = [UIApplication sharedApplication].windows;
    if ([windows count] == 1) {
        return [windows firstObject];
    } else {
        for (UIWindow *window in windows) {
            if (window.windowLevel == UIWindowLevelNormal) {
                return window;
            }
        }
    }
    
    return nil;
}

@end
